﻿using System;
using System.Reflection;
using ProgramMain.Google;

namespace ProgramMain.OpticNet
{
    public partial class FrmVertexes : ProgramMain.Framework.frmBase
    {
        public FrmVertexes()
        {
            InitializeComponent();

            UniqueIdent = GenerateFormIdent();
        }

        private static string GenerateFormIdent()
        {
            return GenerateUniqueIdent(MethodInfo.GetCurrentMethod().DeclaringType.Name);
        }

        public static FrmVertexes ShowForm()
        {
            return FrmVertexes.ShowForm(true);
        }

        public static FrmVertexes ShowForm(bool Refresh)
        {
            string FormIdent = GenerateFormIdent();
            FrmVertexes frm = (FrmVertexes)FindForm(FormIdent);
            if (frm != null)
            {
                frm.Activate();
            }
            else
            {
                frm = new FrmVertexes();
                frm.ShowAsMDI(Program.MainForm);
                if (Refresh)
                    frm.RefreshForm();
            }

            return frm;
        }

        public void RefreshForm()
        {
            vertexList1.RefreshControl();
        }

        public void SetActiveVertexForCabel(int? cableBoxID)
        {
            vertexList1.SetActiveRow(cableBoxID);
            vertexList1.CurveElemrntID = cableBoxID;
            panelShowAll.Visible = true;
            RefreshForm();
        }

        public void SetActiveVertex(int? vertexID)
        {
            vertexList1.SetActiveRow(vertexID);
            vertexList1.DetailID = vertexID;
            panelShowAll.Visible = true;
            RefreshForm();
        }
        public void SetPath(int? fibreID)
        {
          
            vertexList1.FibreID = fibreID;
            panelShowAll.Visible = true;
            RefreshForm();
        }

        public void SetNearPoint(Coordinate coordinate, int coordinateTolerance)
        {
            vertexList1.nearCoordinate = coordinate;
            vertexList1.coordinateTolerance = coordinateTolerance;
            panelShowAll.Visible = true;
            RefreshForm();
        }

        public void SetCable(int? cableID)
        {
            vertexList1.CurveElemrntID = cableID;
            panelShowAll.Visible = true;
            RefreshForm();
        }

        public void CableConnection(int? cableID)
        {
            SetCable(cableID);
            vertexList1.ConnectionVertexes();
        }

        private void btnShowAll_Click(object sender, EventArgs e)
        {
            panelShowAll.Visible = false;
            vertexList1.nearCoordinate = null;
            vertexList1.CurveElemrntID = null;
            vertexList1.FibreID = null;
            vertexList1.DetailID = null;
            RefreshForm();
        }

        private void vertexList1_ViewRowIDChanged(object sender, Framework.BaseDetailCtl.ShowDetailEventArgs e)
        {
            cableBoxList1.DetailID = e.DetailID;
            equipmentList1.DetailID = e.DetailID;
            cableList1.DetailID = e.DetailID;
        }

        public void SetTableActive(Framework.PresentFormType present)
        {
            switch (present)
            {
                case Framework.PresentFormType.InCableBoxes :
                    tabControlVertexDetail.SelectedTabPage = tabCableBox;
                    break;
                case Framework.PresentFormType.InEquipment :
                    tabControlVertexDetail.SelectedTabPage = tabEquip;
                    break;
                case Framework.PresentFormType.InCables :
                    tabControlVertexDetail.SelectedTabPage = tabCable;
                    break;
            }
        }
    }
}